package bsserver.response;

import bsserver.Main;
import bsserver.Request;
import java.util.Date;

/**
 * Response class for handling Client/Server Error Responses
 * @author tblackstone
 */
public class ErrorResponse extends Response {

    /**
     * Create a new Error Response to a given request
     * @param r the Request which caused this Response to be generated
     * @param status the status code to return to the client
     */
    public ErrorResponse(Request r, int status) {
        super(r);

        setStatus(status);
        setDefaultHeaders();
        setHeader("Content-language", "en");
        setHeader("Content-type", "text/html; charset=ISO-8859-1");

        String responseText = responseCodes.get(status);

        String body =
                "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" +
                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n" +
                "  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" +
                "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n" +
                "<head>\n" +
                "  <title>" + status + ": " + responseText + "</title>\n" +
                "</head>\n" +
                "<body>\n" +
                "  <h1>" + status + "</h1>\n" +
                "  <h3>" + responseText + "</h3>\n" +
                "  <hr />\n" +
                "<span>" + (new Date().toString()) + "</span>\n" +
                "<span>" + Main.getServerInfo() + "</span>\n" +
                "</body>\n" +
                "</html>\n";

        setBody(body);

    }
}
